import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('Bg')
export class Bg extends Component {

    @property(Node)
    bg1:Node = null;

    @property(Node)
    bg2:Node = null;
    
    @property
    speed:number = 100;

    start() {

    }

    update(deltaTime: number) {
        let position1 = this.bg1.position;
        this.bg1.setPosition(position1.x,position1.y-this.speed*deltaTime,position1.z)
        let position2 = this.bg2.position;
        this.bg2.setPosition(position2.x,position2.y-this.speed*deltaTime,position2.z)

        let p1 = this.bg1.position
        let p2 = this.bg2.position
        if (p1.y <= -852) {
            this.bg1.setPosition(p1.x,p1.y+852*2,p1.z)
        }
        if (p2.y <= -852) {
            this.bg2.setPosition(p2.x,p2.y+852*2,p2.z)
        }
    }
}


